package com.levi.controller;

import com.levi.pojo.SysUser;
import com.levi.service.SysUserService;
import com.levi.util.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class UserController {

	@Autowired
	SysUserService userService;

	@GetMapping("/none")
	public String test(HttpServletRequest request) {
		return "这个接口不拦截";
	}

	/**
	 * 获取用户
	 * @param request
	 * @return
	 */
	@GetMapping("user/{id}")
	@PreAuthorize("hasAuthority('auth:user')")
	public SysUser getUser(HttpServletRequest request, @PathVariable Integer id) {
		return userService.getById(id);
	}
	
	/**
	 * 获取登陆人
	 * @return
	 */
	@GetMapping("/user/loginUser")
	public String getLoginUser() {
		return SecurityUtils.getCurrentUsername();
	}

	@GetMapping("/role/get")
	@PreAuthorize("hasAuthority('auth:role')")
	public String getRole() {
		return "拥有role权限可访问到";
	}

	@GetMapping("/menu/get")
	@PreAuthorize("hasAuthority('auth:menu')")
	public String getMenu() {
		return "拥有menu权限可访问到";
	}
	
}
